﻿using CarPCBATest.Procedure;
using CarPCBATest.ViewModel;
using Common;
using MahApps.Metro.Controls;
using System;
using VM.Core;

namespace CarPCBATest.View
{
    /// <summary>
    /// MainView.xaml 的交互逻辑
    /// </summary>
    public partial class MainView : MetroWindow
    {
        public MainView()
        {
            InitializeComponent();
            this.DataContext = new MainViewModel();
        }

        public MainView(string licenseMessage)
        {
            InitializeComponent();
            var tmp = licenseMessage.Split(new char[] { ',' });
            tbLicenseDate.Text = tmp[0];
            tbLicenseLeftTime.Text = tmp[1];
            this.DataContext = new MainViewModel();
            this.Title = PcbConfigHelper.Load().Title;
        }

        public MainView(string licenseMessage, string sn)
        {
            InitializeComponent();
            var tmp = licenseMessage.Split(new char[] { ',' });
            tbLicenseDate.Text = tmp[0];
            tbLicenseLeftTime.Text = tmp[1];
            this.DataContext = new MainViewModel();
            this.Title = PcbConfigHelper.Load().Title;
            this.tbSN.Text = sn;
        }

        private void HamburgerMenuControl_OnItemInvoked(object sender, HamburgerMenuItemInvokedEventArgs e)
        {
            this.HamburgerMenuControl.Content = e.InvokedItem;
        }

        private void MetroWindow_Closed(object sender, System.EventArgs e)
        {
            try
            {
                Global.CANfd.Close();
                VmSolution.Instance?.Dispose();
                CameraTool.Close();
                Environment.Exit(0);
            }
            catch (Exception ex)
            {
                Mylog.Error(ex);
                Environment.Exit(0);
            }
        }
    }
}